package com.example.jetpacktest.viewbinding

import android.os.Bundle
import android.os.PersistableBundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.example.jetpacktest.databinding.ActivityViewBindingTest1Binding

class ViewBindingTest1Activity: AppCompatActivity() {

    /**
     * ActivityViewBindingTest1Binding是android自动生成的，layout文件名后面加上Binding
     * 本Activity的layout文件名activity_view_binding_test1.xml
     */
    private lateinit var binding: ActivityViewBindingTest1Binding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityViewBindingTest1Binding.inflate(layoutInflater)
        setContentView(binding.root)
        init()
    }

    private fun init(){
        binding.text1.text = "111"
        binding.btn1.setOnClickListener {
            Toast.makeText(this, "点击了按钮", Toast.LENGTH_SHORT).show()
        }
    }

}